package org.zcl.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.zcl.entity.po.AwardRecord;
import org.zcl.entity.model.ApiResponse;
import org.zcl.service.AwardRecordService;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * 奖记录控制器
 *
 * @author Chenglin Zhu
 * @date 2022/09/07 13:57
 * @since 2022-01-28 15:00:19
 */
@Api(value = "awardRecord", tags = {"奖记录控制器"})
@RestController
@RequestMapping("awardRecord")
public class AwardRecordController extends BaseAction {
    /**
     * 服务对象
     */
    @Resource
    private AwardRecordService awardRecordService;

    /**
     * 分页查询所有数据
     *
     * @param page        分页对象
     * @param awardRecord 查询实体
     * @return 所有数据
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Page<AwardRecord>", name = "page", value = "分页对象"),
            @ApiImplicitParam(paramType = "query", dataType = "AwardRecord", name = "awardRecord", value = "查询实体")
    })
    @ApiOperation(value = "分页查询所有数据", notes = "分页查询所有数据", httpMethod = "GET")
    @GetMapping
    public ApiResponse<Page<AwardRecord>> selectAll(Page<AwardRecord> page, AwardRecord awardRecord) {
        return returnSuccess(this.awardRecordService.page(page, new QueryWrapper<>(awardRecord)));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "Serializable", name = "id", value = "主键")
    })
    @ApiOperation(value = "通过主键查询单条数据", notes = "通过主键查询单条数据", httpMethod = "GET")
    @GetMapping("{id}")
    public ApiResponse<AwardRecord> selectOne(@PathVariable Serializable id) {
        return returnSuccess(this.awardRecordService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param awardRecord 实体对象
     * @return 新增结果
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "AwardRecord", name = "awardRecord", value = "实体对象")
    })
    @ApiOperation(value = "新增数据", notes = "新增数据", httpMethod = "POST")
    @PostMapping
    public ApiResponse<Boolean> insert(@RequestBody AwardRecord awardRecord) {
        return returnSuccess(this.awardRecordService.save(awardRecord));
    }

    /**
     * 修改数据
     *
     * @param awardRecord 实体对象
     * @return 修改结果
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "AwardRecord", name = "awardRecord", value = "实体对象")
    })
    @ApiOperation(value = "修改数据", notes = "修改数据", httpMethod = "PUT")
    @PutMapping
    public ApiResponse<Boolean> update(@RequestBody AwardRecord awardRecord) {
        return returnSuccess(this.awardRecordService.updateById(awardRecord));
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "List<Long>", name = "idList", value = "主键结合")
    })
    @ApiOperation(value = "删除数据", notes = "删除数据", httpMethod = "DELETE")
    @DeleteMapping
    public ApiResponse<Boolean> delete(@RequestParam("idList") List<Long> idList) {
        return returnSuccess(this.awardRecordService.removeByIds(idList));
    }
}

